package com.sjb.sixteen_journey_backend.controller;


import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.ChatList;
import com.sjb.sixteen_journey_backend.service.IChatListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 私聊表
 *
 * @author jcz
 * @since 2024-08-17
 */
@RestController
@RequestMapping("/chat-list")
public class ChatListController {
    @Autowired
    private IChatListService chatListService;

    /**
     * 获取私聊记录
     * @param fromId 发送者id
     * @param toId 接收者id
     * @return
     */
    @GetMapping("/chatSingle/{fromId}/{toId}")
    public R<List<ChatList>> chatSingle(@PathVariable("fromId") Integer fromId,@PathVariable("toId") Integer toId) {
        return chatListService.chatSingle(fromId, toId);
    }

    /**
     * 获取未读消息的数量
     * @return
     */
    @GetMapping("/getNotReaderChat")
    public R getNotReaderChat() {
        return chatListService.getCountByFromUserId();
    }

    /**
     * 修改未读消息为已读
     * @param id 接收者id
     * @return
     */
    @PatchMapping("/changeNotReaderChat/{id}")
    public R changeNotReaderChat(@PathVariable("id") Integer id) {
        return chatListService.changeNotReaderChat(id);
    }

    /**
     * 五分钟内撤回私聊记录
     * @param id 私聊记录id
     * @return
     */
    @DeleteMapping("/deleteChat/{id}")
    public R deleteChat(@PathVariable("id") Integer id) {
        return chatListService.deleteChat(id);
    }
}
